<template>
  <!-- 宿舍分配记录页面 -->
  <div class="app-container">
    <!-- 搜索 -->
    <searchForm :formOptions="formOptions" @onSearch="onSearch" @onReset="onReset" v-show="showSearch"
      :formLabelWidth="formLabelWidth">
<!--      <el-form-item label="所在院部：">-->
<!--        <el-cascader v-model="queryParams.deptId" :options="deptOptions"-->
<!--          :props="{ value: 'id', currentLabels: 'label', checkStrictly: true }" @change="handleChange"></el-cascader>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所选专业：">-->
<!--        <el-select v-model="queryParams.specialityId" clearable placeholder="请选择">-->
<!--          <el-option v-for="item in profession" :key="item.VALUE" :label="item.TITILE" :value="item.VALUE"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="所在年级：">-->
<!--        <el-select v-model="queryParams.gradeId" clearable placeholder="请选择">-->
<!--          <el-option v-for="item in gradeDate" :key="item.VALUE" :label="item.TITILE" :value="item.VALUE"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="学生性别：">-->
<!--        <el-select v-model="queryParams.sex" placeholder="请选择学生性别" style="width: 200px">-->
<!--          <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label" :value="dict.value">-->
<!--          </el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
    </searchForm>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table :data="allocationInfolist" v-loading="loading">
      <el-table-column prop="college" show-overflow-tooltip width="140" label="院系"> </el-table-column>
      <el-table-column prop="specialityName" width="140"  label="专业" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="className" width="160" label="班级" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="studentName" width="80" label="学生姓名" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="name" width="80" label="性别" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column prop="houseName" width="80" label="楼号" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="roomNo" width="80" label="房间号" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="studentNo" width="100" label="注册号" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="createName" width="80" label="分配人" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="createTime" width="140" label="分配时间" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="allocationType" width="80" label="分配方式" show-overflow-tooltip> </el-table-column>
      <el-table-column prop="changeReason" label="操作原因" show-overflow-tooltip> </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import searchForm from "../../components/Search/searchForm.vue";
import { deptTreeSelect } from "@/api/system/user";
import { getSpecialityByDeptId } from "@/api/information/unitMajor";
import { getGradeSelect } from "@/api/information/gradeInfor";
import { mapState, mapActions } from 'vuex'

export default {
  components: { searchForm },
  dicts: ["sys_normal_disable"],
  data() {
    return {
      formLabelWidth: "80px",
      formOptions: [
        {
          label: "姓名",
          prop: "studentname",
          element: "el-input",
          placeholder: "请输入姓名",
        },
        {
          label: "注册号",
          prop: "studentNo",
          element: "el-input",
          placeholder: "请输入注册号",
        },
      ],
      tableData: [],
      total: 0,
      showSearch: true,
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        specialityId: null,
        deptId: null,
        gradeId: null,
        sex: null,
        studentname:null
      },
      form: {
        deptId: ''
      },
      deptOptions: [],
      profession: [],
      gradeDate: []
    };
  },
  dicts: ["sys_user_sex"],

  created() {
    this.getList();
    this.department();
    this.getGradeInfor()
  },
  computed: {
    ...mapState({
      allocationInfolist: state => state.roomBedList.userBedLog,
    })
  },
  methods: {
    ...mapActions({
      getDormAllocationInfolist: 'roomBedList/getuserBedLog'
    }),
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      const arr = Object.assign(this.queryParams, val);
      console.log(arr);
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置
    onReset(data) {
      this.queryParams.pageNum = 1;
      const arr = Object.assign(this.queryParams, data);
      Object.assign(this.queryParams, this.$options.data().queryParams);
      debugger
      this.getList();
    },
    /** 查询角色列表 */
    async getList() {
      this.loading = true;
      await this.getDormAllocationInfolist(this.queryParams).then(res => {
        this.total = res.total
        this.loading = false
      });;
      // listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
      //   (response) => {
      //     this.tableData = response.rows;
      //     this.total = response.total;
      //   }
      // );
    },

    // 获取部门信息
    async department() {
      await deptTreeSelect().then(res => {
        this.deptOptions = res.data;
      });
    },

    // 下拉树选择
    handleChange(value) {
      if (typeof value == "object") {
        this.form.deptId = value[value.length - 1];
        this.queryParams.deptId = value[value.length - 1];
        this.getSpeciality();
      } else if (typeof value == "number") {
        this.form.deptId = value;
        this.getSpeciality();
      } else if (value == undefined) {
        this.form.specialityId = "";
      }
    },

    // 查找专业
    getSpeciality() {
      if (this.form.deptId) {
        getSpecialityByDeptId({ deptId: this.form.deptId }).then(res => {
          if (res.code == "200") {
            this.profession = res.data;
          } else {
            console.log("123");
            this.profession = [];
          }
        });
      } else {
        this.profession = [];
      }
    },


    // 查询所在年级
    getGradeInfor() {
      getGradeSelect().then(response => {
        // console.log(response, "Student");
        this.gradeDate = response.data;
      });
    },
  },
};
</script>

<style></style>
